package com.magicsoft.share.ui.share;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.TextView;

import com.magicsoft.share.R;
import com.magicsoft.share.base.BaseActivity;
import com.magicsoft.share.bean.share.ReportType;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.presenter.share.ReportPresenter;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.utils.ToastUtils;
import com.magicsoft.share.view.share.IReportView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ReportActivity extends BaseActivity<IReportView, ReportPresenter> implements IReportView {


    @BindView(R.id.view_top)
    View viewTop;
    @BindView(R.id.ibtn_left)
    ImageButton ibtnLeft;
    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ibtn_right)
    ImageButton ibtnRight;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_article_title)
    TextView tvArticleTitle;
    @BindView(R.id.cb1)
    CheckBox cb1;
    @BindView(R.id.cb2)
    CheckBox cb2;
    @BindView(R.id.cb3)
    CheckBox cb3;
    @BindView(R.id.cb4)
    CheckBox cb4;
    @BindView(R.id.cb5)
    CheckBox cb5;
    @BindView(R.id.cb6)
    CheckBox cb6;
    @BindView(R.id.cb7)
    CheckBox cb7;
    @BindView(R.id.cb8)
    CheckBox cb8;
    @BindView(R.id.btn_report)
    Button btnReport;
    private String reprotType = "";

    private String articleId;
    private String articleNickname;
    private String articleTitle;
    private String targetId;

    @Override
    public ReportPresenter initPresenter() {
        return new ReportPresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_report;
    }

    @Override
    public void initData() {


        articleId = getIntent().getStringExtra("articleId");
        articleNickname = getIntent().getStringExtra("articleNickname");
        articleTitle = getIntent().getStringExtra("articleTitle");
        targetId = getIntent().getStringExtra("targetId");
    }

    @Override
    public void initView() {
        tvName.setText("举报:" + articleNickname);
        tvArticleTitle.setText(articleTitle);
        tvTitle.setText("举报");

    }

    @Override
    public void requestData() {

        mPresenter.reportType();
    }


    @OnClick({R.id.ibtn_left, R.id.btn_report})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ibtn_left:
                finish();
                break;
            case R.id.btn_report:
                report();
                break;
        }
    }


    @Override
    public void reportSuccess() {
        ToastUtils.showToast(this, "举报成功，我们会尽快处理");
        finish();
    }

    @Override
    public void reportTypeSuccess(List<ReportType> types) {

        cb1.setText(types.get(0).getReport_type_name());
        cb2.setText(types.get(1).getReport_type_name());
        cb3.setText(types.get(2).getReport_type_name());
        cb4.setText(types.get(3).getReport_type_name());
        cb5.setText(types.get(4).getReport_type_name());
        cb6.setText(types.get(5).getReport_type_name());
        cb7.setText(types.get(6).getReport_type_name());
        cb8.setText(types.get(7).getReport_type_name());
    }

    private void report() {
        if (cb1.isChecked() || cb2.isChecked() || cb3.isChecked() || cb4.isChecked() || cb5.isChecked() || cb6.isChecked() || cb7.isChecked() || cb8.isChecked()) {

            if (cb1.isChecked()) {
                reprotType = cb1.getText().toString() + "," + reprotType;
            }
            if (cb2.isChecked()) {
                reprotType = cb2.getText().toString() + "," + reprotType;
            }
            if (cb3.isChecked()) {
                reprotType = cb3.getText().toString() + "," + reprotType;
            }
            if (cb4.isChecked()) {
                reprotType = cb4.getText().toString() + "," + reprotType;
            }
            if (cb5.isChecked()) {
                reprotType = cb5.getText().toString() + "," + reprotType;
            }
            if (cb6.isChecked()) {
                reprotType = cb6.getText().toString() + "," + reprotType;
            }
            if (cb7.isChecked()) {
                reprotType = cb7.getText().toString() + "," + reprotType;
            }
            if (cb8.isChecked()) {
                reprotType = cb8.getText().toString() + "," + reprotType;
            }

            Log.d("lyf", "report: " + reprotType);
            mPresenter.report(Long.valueOf(targetId), Long.valueOf(articleId), reprotType);

        } else {
            ToastUtils.showToast(this, "请选择举报类型");
        }


    }


}
